<?php namespace App\Http\Middleware;
use Auth;
use Illuminate\Http\RedirectResponse;
use Closure;

class Admin {

    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        $user = $request->user();
        //assuming App\User has a method isAdmin().
        if( !Auth::user()->isAdmin)
            return new RedirectResponse(url('/'));

        return $next($request);
    }
}


